<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>后台管理系统</title>
        <meta name="author" content="BaiYY"/>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
        <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
    </head>
<body>
    <div class="right-sidebar" style="max-width: 1200px;">
        <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
            <li role="presentation"><a href="gameRecordList.html">{:L(GAME_RECORD_LIST)}</a></li>
            <li role="presentation" class="active"><a href="gameRecord.html">比赛记录查询</a></li>
        </ul>

        <div class="input-group col-md-12" style="margin: 10px auto;">
            <input type="number" min="0" class="form-control" placeholder="请输入比赛流水号" name="record" id="record">
            <span class="input-group-addon" id="cbtn">查询</span>
        </div>
        <ul style="display: flex;justify-content: space-around;text-align: center;line-height: 40px;">
            <li class="bg-info" style="flex-grow: 1">流水号：<span id="matchNum"></span></li>
            <li style="flex-grow: 1"></li>
            <li class="bg-success" style="flex-grow: 1">时间：<span id="matchTime"></span></li>
        </ul>
        <section class="table-responsive">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>游戏UID</th>
                        <th>微信昵称</th>
                        <th>排名</th>
                    </tr>
                </thead>
                <tbody id="dataList"></tbody>
            </table>
        </section>
    </div>
    <script type="text/javascript">
       $("#cbtn").on("click",function () {
           var record = $.trim( $("#record").val());
           if(record == '' || record == null) {
               alert("比赛流水号不能为空！");
               window.location.href="{:U('Admin/Main/gameRecord')}";
               return false;
           }
           $.ajax({
               type:"get",
               url:"{:U('Admin/Main/getGameRecord')}?record="+record,
               success: function (data) {
//                   console.log(data);
                   if(data == 'error') {
                       $("#dataList").html("暂时没查询到数据");
                   }else{
                       if(data.match == '' || data.match == null) {
                           $("#dataList").html("暂时没查询到数据");
                       }else{
                           $("#matchNum").html(data.match.matchSN);
                           $("#matchTime").html(getLocalTime(data.match.startTime));
                           var res = [];
                           var arr = Object.keys(data.match.users);
                           for(var i=0;i<arr.length;++i) {
                               res.push(data.match.users[arr[i]]);
                           }
                           function  compare(a,b) {
                               var a1 = a.rank;
                               var b1 = b.rank;
                               if(a1 < b1) {
                                   return -1;
                               }else if(a1 > b1) {
                                   return 1;
                               }else{
                                   return 0;
                               }
                           }
                           var str = '';
                           res.sort(compare);
                           for(var j=0;j<res.length;++j) {
                               str += "<tr><td>"+res[j].uid+"</td><td>"+res[j].rank+"</td><td>"+res[j].nick+"</td></tr>";
                           }
                           $("#dataList").html(str);
                       }
                   }
               }
           });
       });
    </script>
</body>
</html>